layui.config({
    base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'form'], function(){
    var $ = layui.$, form = layui.form;

    var id = $('#id').val();
    var data = {'id': id};
    post('gift/toEdit', data, false,function (data) {
        var gift = data.gift;
        $('#name').val(gift.name);
        $('#iconImg').attr('src', ossDomain + '/' + gift.icon);
        $('#icon').val(gift.icon);
        $('#coin').val(gift.coin);
        $('#earn').val(gift.earn);
    });

    //加载上传控件
    upload("iconDiv", function (up, file, info) {
        var option = up.getOption();
        var host = option.url;
        var dir = option.multipart_params.key;

        var url = host + '/' + dir;
        $('#iconImg').attr('src', url);
        $('#icon').val(dir);
        $('#iconDel').show();
    });

    //删除图片
    $('#iconDel').on('click', function () {
        $('#iconImg').removeAttr('src');
        $('#icon').val('');
        $('#iconDel').hide();
    });

    //校验
    form.verify({
        'img-verify': function (value, item) {
            var imgSrc = $('#iconImg').attr("src")
            if(imgSrc == '' || imgSrc == undefined){
                return '请上传礼物图片';
            }
        }
    });

});